package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.iview.IUpdatePasswordView;
import com.cloudsigns.factorymanager2.produce.model.IUpdatePasswordModel;
import com.cloudsigns.factorymanager2.produce.model.UpdatePasswordModel;

/**
 * 用户修改密码
 */
public class UpdatePasswordPresenter {
    private IUpdatePasswordView view;
    private IUpdatePasswordModel model;
    private Handler handler = new Handler();

    public UpdatePasswordPresenter(IUpdatePasswordView view) {
        this.view = view;
        this.model = new UpdatePasswordModel();
    }

    public void updatePassword() {
        model.updatePassword(view.getNpassword(), view.getOldPassword(), new UpdatePasswordModel.OnUpdatePasswordListener() {
            @Override
            public void successed() {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getUpdatePasswordSuccessed();
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getUpdatePasswordFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
